package com.guiji.quartz.task;

import cn.hutool.core.util.ReflectUtil;
import com.guiji.quartz.domain.WangyiNews;
import com.guiji.quartz.domain.Zongyi360;
import org.quartz.simpl.SimpleThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.model.ConsolePageModelPipeline;
import us.codecraft.webmagic.model.OOSpider;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @program: cms-vue-plus
 * @description:
 * @author: gaoX
 * @create: 2021-08-30 11:50
 **/
@Component("zongyi360Task")
public class Zongyi360Task {
	private static final Logger log = LoggerFactory.getLogger(Zongyi360Task.class);

//	@Scheduled(cron = "10 * * * * ?")
	public void zongyi360Task() throws IllegalAccessException {
		Long startTime = System.currentTimeMillis();
		Spider spider = OOSpider.create(Site.me().setSleepTime(1000), new ConsolePageModelPipeline(), Zongyi360.class)
			.addUrl("https://yule.360.com/")
			.thread(20);
		spider.run();
		log.info("zongyi360Task-end-:{}",System.currentTimeMillis()-startTime);

		Field availWorkers = ReflectUtil.getField(SimpleThreadPool.class, "availWorkers");
		List ls = new ArrayList();
		List list = (List) availWorkers.get(ls);

		log.info("availWorkers-size-:{}",list.size());

	}
}
